import { Component, OnInit, ViewChild, Input } from '@angular/core';
import { NzModalRef, NzMessageService, NzNotificationService } from 'ng-zorro-antd';
import { _HttpClient } from '@delon/theme';
import { SFSchema, SFUISchema, SFComponent, SFUISchemaItem } from '@delon/form';
import { Observable, of, zip } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { STColumn, STColumnTag, STColumnBadge } from '@delon/abc';

export const TAG_JOB_TYPE: STColumnTag = {
  '1': { text: 'Java', color: 'blue' },
  '2': { text: 'SpringBean', color: 'red' },
  '3': { text: 'Http', color: 'green' },
  '4': { text: 'Jar', color: 'lime' },
};
export const TAG_JOB_MISFIRE: STColumnTag = {
  '1': { text: '错失周期立即执行', color: 'blue' },
  '2': { text: '错失周期执行一次', color: 'red' },
  '3': { text: '下周期执行', color: 'green' },
};

export const BADGE_JOB_STATUS: STColumnBadge = {
  '1': { text: '未发布', color: 'default' },
  '2': { text: '已发布', color: 'success' },
  '3': { text: '暂停', color: 'warning' },
};

export const BADGE_JOB_EXEC_STATUS: STColumnBadge = {
  '0': { text: '正常', color: 'success' },
  '1': { text: '异常', color: 'error' },
};

/**
 * 作业日志
 */
@Component({
  selector: 'app-quartz-job-log',
  templateUrl: './job-log.component.html',
})
export class JobLogComponent implements OnInit {
  @Input()
  record: any = {};
  params = { jobId: '' };
  url = `/cf/job/sys-job/job-log?descs=create_time`;
  columns: STColumn[] = [
    { title: '任务名', index: 'jobName' },
    { title: '组名', index: 'jobGroup' },
    { title: '状态', index: 'jobLogStatus', type: 'badge', badge: BADGE_JOB_EXEC_STATUS },
    { title: '类型', index: 'jobType', type: 'tag', tag: TAG_JOB_TYPE },
    { title: '执行路径', index: 'executePath', render: 'path', width: 100 },
    { title: '执行文件', index: 'className', render: 'clazz', width: 100 },
    { title: '执行方法', index: 'methodName', render: 'method', width: 100 },
    { title: '执行参数', index: 'methodParamsValue', render: 'param', width: 100 },
    { title: 'cron', index: 'cronExpression', render: 'cron', width: 100 },
    { title: '状态描述', index: 'jobMessage' },
    { title: '耗时(ms)', index: 'executeTime' },
    { title: '异常信息', index: 'exceptionInfo', render: 'except', width: 100 },
    { title: '开始时间', index: 'createTime', width: 150 },
  ];

  constructor(
    private modal: NzModalRef,
    private msgSrv: NzMessageService,
    public http: _HttpClient,
    private notice: NzNotificationService,
  ) {}

  ngOnInit() {
    this.params.jobId = this.record.jobId;
  }
}
